<template>
	<div id="">
		<el-form :inline="true" size="medium">
			<el-form-item>
				<el-select 
					v-model="params.tenantId" 
					placeholder="选择分站" 
					@change="search"
					clearable>
					<el-option 
					v-for="item in tenantList" 
					:label="item.company" 
					:value="item.id"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-select v-model="params.status" placeholder="状态" clearable @change="search">
					<el-option value="0" label="处理中"></el-option>
					<el-option value="1" label="已处理"></el-option>
				</el-select>
			</el-form-item>
			<el-form-item>
				<el-input placeholder="商家ID" v-model="params.busId" clearable></el-input>
			</el-form-item>
			<el-form-item>
				<el-button type="primary" @click="search">搜索</el-button>
			</el-form-item>
		</el-form>

		<el-table :data="list" v-loading="loading" stripe>
			<el-table-column label="id" prop="id" align="center"></el-table-column>
			<el-table-column 
				label="分站"
				align="center">
				<template slot-scope="scope">
					<span v-for="item in tenantList" v-if="item.id == scope.row.tenant_id">{{item.company}}</span>
				</template>
			</el-table-column>
			<el-table-column label="商家id" prop="bus_id" align="center"></el-table-column>
			<el-table-column label="快递单号" prop="express_nos" align="center"></el-table-column>
			<el-table-column label="接收邮箱" prop="email" align="center"></el-table-column>
			<el-table-column label="创建时间" align="center">
				<template slot-scope="scope">
					{{$moment(scope.row.create_time).format('Y-MM-DD HH:mm')}}
				</template>
			</el-table-column>
			<el-table-column label="操作" align="center">
				<template slot-scope="scope">
					<span v-if="scope.row.status == 1">已处理</span>
					<el-button v-else type="primary" size="small" @click="updateStatus(scope.row)">处理</el-button>
				</template>
			</el-table-column>
		</el-table>

		<el-pagination 
			class="page"
			background
			@size-change="handleSizeChange" 
			@current-change="getList" 
			:current-page.sync="params.pageNo" 
			:page-sizes="[10, 20, 50, 100]" 
			:page-size="params.pageSize" 
			layout="total, sizes, prev, pager, next, jumper" 
			:total="total">
		</el-pagination>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				params: {
					pageNo: 1,
					pageSize: 10,
					isCount: true,
					tenantId: '',
					busId:'',
					endTime: '' ,
					startTime: '',
					status:'0',
				},
				list: [],
				total: 0,
				loading: false,
				selectData: [],
				tenantList: [],
				timeArr: []
			};
		},

		watch: {},

		created() {
			this.getTenantList()
		},

		mounted() {
			this.getList();
		},

		methods: {
			updateStatus(row){
				this.$request.post({
					url:'/ReportApi/admin/userbottomsheetlistupdate',
					params:{
						id: row.id
					},
					success: res => {
						this.$message.success('操作成功')
						row.status = 1
					}
				})
			},
			handleSizeChange(value) {
				this.params.pageSize = value 
				this.search()
			},
			getTenantList(){
				this.$request.post({
					url: '/ReportApi/admin/useralllist',
					success: res => {
						this.tenantList = res
					}
				})
			},
			search(){
				this.params.pageNo = 1
				this.params.isCount = true 
				this.getList();
			},
			timeChange(val){
				if(val){
					this.params.startTime = this.$common.getDate(val[0]);
					this.params.endTime = this.$common.getDate(val[1]);
				}else{
					this.params.startTime = ''
					this.params.endTime = ''
				}
			},
			getList() {
				this.loading = true
				this.$request.post({
					url: '/ReportApi/admin/userbottomsheetlist',
					params: this.params,
					success: result =>{
						this.list = result[0] 
						if(this.params.isCount){
							this.params.isCount = false 
							this.total = result[1]
						}
					},
					finally: ()=>{
						this.loading = false 
					}
				})
			}
		},

		beforeDestroy() {}
	}
</script>

<style>

</style>

<style lang="scss" scoped>
	.page{
		text-align: right;
		margin-top: 20px;
	}
</style>
